/**
 * 
 */
package edu.hm.compiler.interpreter.renamer;

import java.util.ArrayList;
import java.util.List;

import edu.hm.compiler.parser.grammar.BodyOption;
import edu.hm.compiler.parser.grammar.Head;
import edu.hm.compiler.parser.grammar.Rule;
import edu.hm.compiler.parser.grammar.predicate.Predicate;

/**
 * @author Korny
 */
public class RuleRenamer extends Renamer< Rule >
{

    /**
     * @param rule
     */
    public RuleRenamer( final Rule rule )
    {

        super( rule );
    }

    /**
     * @return
     */
    @Override
    public Rule rename()
    {
        final Predicate predicate = this.getRuleOrQuery().getHead().getPredicate();
        final Predicate newHead = this.renamePredicate( predicate );
        final List< Predicate > predicateList = this.getRuleOrQuery().getBodyOption().getPredicateList();
        final List< Predicate > newBody = new ArrayList<>();
        for( final Predicate p: predicateList )
            newBody.add( this.renamePredicate( p ) );

        final Rule newRule = new Rule( new Head( newHead ), new BodyOption( newBody ) );

        return newRule;
    }
}
